package main

import (
	"fmt"
	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/context"
	"github.com/sirupsen/logrus"
	"strconv"
)

func main() {
	app := iris.Default()
	app.Get("/hello", func(c *context.Context) {
		c.WriteString("hello")
	})

	party := app.Party("/v1")
	party.Use(func(c *context.Context) {
		logrus.Info("自定义中间件")
		c.Next()
	})

	party.Get("/users/{id:uint64 min(2)}", func(c *context.Context) {
		id := c.Params().GetUint64Default("id", 0)
		c.WriteString(strconv.Itoa(int(id)))
	})

	party.Get("/orders/{action:string prefix(a_)}", func(c *context.Context) {
		action := c.Params().Get("action")
		c.WriteString(action)
	})

	err := app.Run(iris.Addr(":8081"))
	if err != nil {
		fmt.Println(err)
	}
}
